package br.com.gsc.model.tableMapping;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.transaction.annotation.Transactional;


@Entity
@Table(name="tb_companies")
@Transactional
public class Company {
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="company_id")
	long id;
	
	private String name;
	
	private String description;
	
	@OneToMany(mappedBy="company",cascade=CascadeType.ALL)
	private List<Product> listOfProducts = new ArrayList<Product>();
	
	@ManyToMany(mappedBy = "listOfCompanies")
	List<Person> listOfowners = new ArrayList<Person>();
	
	String companyImage = "thumb_default_company.png";

	public String getCompanyImage() {
		return companyImage;
	}
	public void setCompanyImage(String companyImage) {
		this.companyImage = companyImage;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String desc) {
		this.description = desc;
	}
	public List<Product> getListOfProducts() {
		return listOfProducts;
	}
	public void setListOfProducts(List<Product> listOfProducts) {
		this.listOfProducts = listOfProducts;
	}
	public void addProduct(Product prod){
		if(prod.getCompany() == null){
			prod.setCompany(this);
		}
		this.listOfProducts.add(prod);
	}
	
	public List<Person> getListOfowners() {
		return listOfowners;
	}
	
	public void setListOfowners(List<Person> listOfowners) {
		this.listOfowners = listOfowners;
	}
	
	public void addOwner(Admin admin) {
		this.listOfowners.add(admin);
	}
	
	public String toString(){
		return this.getName();
	}

}
